package com.shinhye.elephantsafe.db.dao;

import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;

public class CommonNumberDao {

	public static int getMainCount(SQLiteDatabase db) {
		Cursor cursor = db.rawQuery("select count(*) from classlist", null);
		int count = 0;
		if(cursor.moveToNext()) {
			count = cursor.getInt(0);
		}
		cursor.close();
		return count;
	}
	
	public static int getSubCount(int groupId, SQLiteDatabase db) {
		Cursor cursor = db.rawQuery("select count(*) from table" + groupId, null);
		int count = 0;
		if(cursor.moveToNext()) {
			count = cursor.getInt(0);
		}
		cursor.close();
		return count;
	}
	
	public static String getMainName(int id, SQLiteDatabase db) {
		Cursor cursor = db.rawQuery("select name from classlist where idx=?", new String[]{id + ""});
		String name = null;
		if(cursor.moveToNext()) {
			name = cursor.getString(0);
		}
		cursor.close();
		return name;
	}
	
	public static String[] getSubName(int groupId, int colId, SQLiteDatabase db) {
		Cursor cursor = db.rawQuery("select name,number from table" + groupId + " where _id=?", new String[]{colId + ""});
		String name = null;
		String number = null;
		if(cursor.moveToNext()) {
			name = cursor.getString(0);
			number = cursor.getString(1);
		}
		cursor.close();
		return new String[]{name, number};
	}
	
}
